<?php

namespace app\common\model;

use think\Model;


class Survey extends Model
{

    

    

    // 表名
    protected $name = 'survey';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'medical_history_text',
        'stomach_text',
        'after_dinner_text'
    ];
    

    
    public function getMedicalHistoryList()
    {
        return ['0' => __('Medical_history 0'), '1' => __('Medical_history 1')];
    }

    public function getStomachList()
    {
        return ['1' => __('Stomach 1'), '2' => __('Stomach 2'), '3' => __('Stomach 3')];
    }

    public function getAfterDinnerList()
    {
        return ['1' => __('After_dinner 1'), '2' => __('After_dinner 2'), '3' => __('After_dinner 3')];
    }


    public function getMedicalHistoryTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['medical_history']) ? $data['medical_history'] : '');
        $list = $this->getMedicalHistoryList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStomachTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['stomach']) ? $data['stomach'] : '');
        $list = $this->getStomachList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAfterDinnerTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['after_dinner']) ? $data['after_dinner'] : '');
        $list = $this->getAfterDinnerList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
